<?php
class ModelModuleSattr extends Model {
	//Get all Attributes From 
	public function getAttributes(){
		$query = $this->db->query("SELECT a.attribute_id,a.name,status FROM ".DB_PREFIX."attribute_description AS a
				LEFT JOIN ".DB_PREFIX."sattr AS s ON a.attribute_id=s.attribute_id");
		
		$newArray =array();
		if($query->num_rows){
			$c =0 ;
			foreach($query->rows as $row){
				$newArray[$c]["id"] = $row["attribute_id"];
				$newArray[$c]["name"] = $row["name"];
				$newArray[$c]["status"] = $row["status"];
				$c++;
			}
			return $newArray;
		}		
	}
	public function cleanTable(){
		$this->db->query("TRUNCATE TABLE ".DB_PREFIX."sattr;");
	}
	
	public function updateTable($array){
		$this->cleanTable();
		$string = "";
		$n = count($array);
		$comma = ",";
		foreach($array as $id){
			if($n == 1)
				$comma = "";
			$string .="(".$id.",'checked')".$comma."";
			$n--;
		}
		$this->db->query("INSERT INTO ".DB_PREFIX."sattr (attribute_id,status) VALUES ".$string."");
	}
	
	public function createTable(){
		$query = $this->db->query("CREATE TABLE IF NOT EXISTS ".DB_PREFIX."sattr (
				attribute_id INT(10) NOT NULL,
				status char(20) DEFAULT 'checked')");
	}
	
	public function removeTable(){
		$query = $this->db->query("DROP TABLE ".DB_PREFIX."sattr");
	}
}
?>